package com.huabo.contract.service.impl;

import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.oracle.entity.TblCyhwUnit;
import com.huabo.contract.oracle.entity.TblLegalArbitratsettlement;
import com.huabo.contract.oracle.mapper.TblLegalArbitratsettlementMapper;
import com.huabo.contract.service.TblLegalArbitratsettlementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Service
public class TblLegalArbitratsettlementServiceImpl implements TblLegalArbitratsettlementService {

    @Resource
    private TblLegalArbitratsettlementMapper tblLegalArbitratsettlementMapper;

    @Override
    public TblLegalArbitratsettlement findById(Integer arbitraId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblLegalArbitratsettlementMapper.findByArbitraId(arbitraId);
        } else {
            return tblLegalArbitratsettlementMapper.findByArbitraId(arbitraId);
        }
    }

    @Override
    public TblCyhwUnit findContractByDisputeId(BigDecimal disputeId){
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblLegalArbitratsettlementMapper.findContractByDisputeId(disputeId);
        } else {
            return tblLegalArbitratsettlementMapper.findContractByDisputeId(disputeId);
        }
    }

    @Override
    public void findListByPageInfo(PageInfo<TblLegalArbitratsettlement> pageInfo,TblLegalArbitratsettlement negotia,Integer disputeid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalArbitratsettlementMapper.findListByPageInfo(pageInfo, negotia, disputeid));
            pageInfo.setTotalRecord(tblLegalArbitratsettlementMapper.findListByPageInfoCount(negotia, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalArbitratsettlementMapper.findListByPageInfo(pageInfo, negotia, disputeid));
            pageInfo.setTotalRecord(tblLegalArbitratsettlementMapper.findListByPageInfoCount(negotia, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        }
    }

    @Override
    public void addDiputregistration(TblLegalArbitratsettlement arbitrat) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {

//        if (attids != null && !"".equals(attids)) {
//            List<TblAttachment> attList = new ArrayList(0);
//            String[] attid = attids.split(",");
//            TblAttachment att = null;
//            String[] var6 = attid;
//            int var7 = attid.length;
//
//            for(int var8 = 0; var8 < var7; ++var8) {
//                String id = var6[var8];
//                att = new TblAttachment();
//                att.setAttid(new BigDecimal(id));
//                attList.add(att);
//            }
//
//            arbitrat.setAttList(attList);
//        }
            tblLegalArbitratsettlementMapper.saveDiputergistration(arbitrat);
        } else {
            tblLegalArbitratsettlementMapper.saveDiputergistration(arbitrat);
        }
    }

    @Override
    public void removeLegalNegotiatedSettlemen(Integer arbitrat) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalArbitratsettlementMapper.removeLegalNegotiatedSettlemen(arbitrat);
        } else {
            tblLegalArbitratsettlementMapper.removeLegalNegotiatedSettlemen(arbitrat);
        }
    }

    @Override
    public void modifyNegotiatedSettlement(TblLegalArbitratsettlement oldArbitrat) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalArbitratsettlementMapper.modifyNegotiatedSettlement(oldArbitrat);
        } else {
            tblLegalArbitratsettlementMapper.modifyNegotiatedSettlement(oldArbitrat);
        }
    }

    @Override
    public TblLegalArbitratsettlement findByarbitraid(Integer arbitraId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblLegalArbitratsettlementMapper.findByarbitraid(arbitraId);
        } else {
            return tblLegalArbitratsettlementMapper.findByarbitraid(arbitraId);
        }
    }
}
